package com.example.wuqujingdianphone.fragment.bookcity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.example.wuqujingdianphone.MyApplication;
import com.example.wuqujingdianphone.R;
import com.example.wuqujingdianphone.activity.BookDetailActivity;
import com.example.wuqujingdianphone.activity.MainActivity;
import com.example.wuqujingdianphone.activity.MiddleActivity;
import com.example.wuqujingdianphone.activity.ShuyouhuiActivity;
import com.example.wuqujingdianphone.adapter.BCHomeAdapter;
import com.example.wuqujingdianphone.adapter.HomeFenleiAdapter;
import com.example.wuqujingdianphone.base.BaseFragment;
import com.example.wuqujingdianphone.bean.BookDetailParcelable;
import com.example.wuqujingdianphone.bean.BookHomeListBean;
import com.example.wuqujingdianphone.bean.BookListBean2;
import com.example.wuqujingdianphone.bean.HomeFenBean;
import com.example.wuqujingdianphone.utils.AssetsUtils;
import com.example.wuqujingdianphone.utils.GsonUtil;
import com.example.wuqujingdianphone.utils.NiceDialogUtils;
import com.example.wuqujingdianphone.utils.ToastUtil;
import com.example.wuqujingdianphone.utils.zxing.OnQRCodeListener;
import com.example.wuqujingdianphone.utils.zxing.QRCodeManager;
import com.example.wuqujingdianphone.view.GlideImageLoader;
import com.example.wuqujingdianphone.view.ScrollGridLayoutManager;
import com.example.wuqujingdianphone.view.banner.Banner;
import com.example.wuqujingdianphone.view.banner.BannerConfig;
import com.example.wuqujingdianphone.view.banner.Transformer;
import com.example.wuqujingdianphone.view.banner.listener.OnBannerListener;
import com.vise.xsnow.http.ViseHttp;
import com.vise.xsnow.http.callback.ACallback;
import com.vise.xsnow.http.mode.CacheMode;
import com.vise.xsnow.http.mode.CacheResult;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by 29083 on 2018/4/10.
 * <p>
 * 书城--首页
 */

public class BookCityHomeFragment extends BaseFragment implements OnBannerListener {
    private static final String TAG = "BookCityHomeFragment";
    @BindView(R.id.recyclerView1)
    RecyclerView mRecyclerView1;
    @BindView(R.id.recyclerView2)
    RecyclerView mRecyclerView2;
    @BindView(R.id.recyclerView3)
    RecyclerView mRecyclerView3;


    private boolean isFirstLoadDate;

    private BCHomeAdapter mAdapter1, mAdapter2, mAdapter3;

    //轮播
    private List<Integer> listUrl = new ArrayList<>();

    //5个分类
    private RecyclerView fenleiRecyclerView;
    private List<HomeFenBean.ObjBean.FenleiListBean> fenleiHomeBeanList = new ArrayList<>();
    private HomeFenleiAdapter fenleiAdapter;


    public static BookCityHomeFragment getBookCityHomeFragment() {
        BookCityHomeFragment fragment = new BookCityHomeFragment();
        return fragment;
    }


    @Override
    protected View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_book_shop_home, null);
//        TextView textView = (TextView) getActivity().findViewById(R.id.title);
//        textView.setText("书城");
        return view;
    }

    @Override
    protected void initData() {
        Log.i(TAG, "initData: ");
        isFirstLoadDate = true;
        initView();
    }


    @Override
    protected void lazyLoad() {
        Log.i(TAG, "lazyLoad: ");
        if (isFirstLoadDate) {
            isFirstLoadDate = false;
            getDataFromService1();
        }
    }


    private void initView() {
        mRecyclerView1.setLayoutManager(new GridLayoutManager(getActivity(), 3));
        mAdapter1 = new BCHomeAdapter(getActivity(), null);
        mRecyclerView1.setAdapter(mAdapter1);
        mAdapter1.addHeaderView(getHeaderView1(), 0);
        mAdapter1.addHeaderView(getHeaderView2(), 1);
        mAdapter1.addFooterView(getFooterView1(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TextView textView = (TextView) v.findViewById(R.id.foot_view);

                Log.i(TAG, "onClick: ");
                loadDataAllNumber = loadDataNumber * loadNumber;
                loadNumber++;


                if (allCacheData.size() >= loadDataAllNumber) {
                    newListBean2s.clear();
                    for (int i = 0; i < loadDataAllNumber; i++) {
                        newListBean2s.add(allCacheData.get(i));
                    }
                    mAdapter1.setNewData(newListBean2s);
                } else {
                    for (int i = allCacheData.size() - surplusNumber; i < allCacheData.size(); i++) {
                        newListBean2s.add(allCacheData.get(i));
                    }
                    mAdapter1.setNewData(newListBean2s);
                    textView.setVisibility(View.GONE);
                    Log.i(TAG, "onClick: 没有更多数据啦");
                }

            }
        }));
        mAdapter1.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Log.i(TAG, "onItemClick: position=" + position);

               /* BookHomeListBean item = mAdapter1.getItem(position);
                BookDetailParcelable bookDetailBean = new BookDetailParcelable();
                bookDetailBean.id = item.id;
                bookDetailBean.spic = item.spic;
                bookDetailBean.title = item.news_tit;

                bookDetailBean.news_source = item.news_source;
                bookDetailBean.jianjie = item.jianjie;
                bookDetailBean.url = item.url;

                Intent intent = new Intent(getActivity(), BookDetailActivity.class);
                intent.putExtra("bookDetail", bookDetailBean);
                startActivity(intent);*/


                Intent intent = new Intent(getActivity(), BookDetailActivity.class);
                intent.putExtra("bookId", mAdapter1.getItem(position).id);
                intent.putExtra("bookTitle", mAdapter1.getItem(position).news_tit);
                startActivity(intent);

            }
        });


        mRecyclerView2.setLayoutManager(new GridLayoutManager(getActivity(), 3));
        mAdapter2 = new BCHomeAdapter(getActivity(), null);
        mRecyclerView2.setAdapter(mAdapter2);
        mAdapter2.addFooterView(getFooterView2(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TextView textView = (TextView) v.findViewById(R.id.foot_view);

                Log.i(TAG, "onClick: ");
                loadDataAllNumber2 = loadDataNumber2 * loadNumber2;
                loadNumber2++;


                if (allCacheData2.size() >= loadDataAllNumber2) {
                    newListBean2s2.clear();
                    for (int i = 0; i < loadDataAllNumber2; i++) {
                        newListBean2s2.add(allCacheData2.get(i));
                    }
                    mAdapter2.setNewData(newListBean2s2);
                } else {
                    for (int i = allCacheData2.size() - surplusNumber2; i < allCacheData2.size(); i++) {
                        newListBean2s2.add(allCacheData2.get(i));
                    }
                    mAdapter2.setNewData(newListBean2s2);
                    textView.setVisibility(View.GONE);
                    Log.i(TAG, "onClick: 没有更多数据啦");
                }

            }
        }));
        mAdapter2.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Log.i(TAG, "onItemClick: position=" + position);
                Intent intent = new Intent(getActivity(), BookDetailActivity.class);
                intent.putExtra("bookId", mAdapter2.getItem(position).id);
                intent.putExtra("bookTitle", mAdapter2.getItem(position).news_tit);
                startActivity(intent);


            }
        });


        mRecyclerView3.setLayoutManager(new GridLayoutManager(getActivity(), 3));
        mAdapter3 = new BCHomeAdapter(getActivity(), null);
        mRecyclerView3.setAdapter(mAdapter3);
        mAdapter3.addFooterView(getFooterView3(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TextView textView = (TextView) v.findViewById(R.id.foot_view);

                Log.i(TAG, "onClick: ");
                loadDataAllNumber3 = loadDataNumber3 * loadNumber3;
                loadNumber3++;


                if (allCacheData3.size() >= loadDataAllNumber3) {
                    newListBean2s3.clear();
                    for (int i = 0; i < loadDataAllNumber3; i++) {
                        newListBean2s3.add(allCacheData3.get(i));
                    }
                    mAdapter3.setNewData(newListBean2s3);
                } else {
                    for (int i = allCacheData3.size() - surplusNumber3; i < allCacheData3.size(); i++) {
                        newListBean2s3.add(allCacheData3.get(i));
                    }
                    mAdapter3.setNewData(newListBean2s3);
                    textView.setVisibility(View.GONE);
                    Log.i(TAG, "onClick: 没有更多数据啦");
                }

            }
        }));
        mAdapter3.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Log.i(TAG, "onItemClick: position=" + position);
                Intent intent = new Intent(getActivity(), BookDetailActivity.class);
                intent.putExtra("bookId", mAdapter3.getItem(position).id);
                intent.putExtra("bookTitle", mAdapter3.getItem(position).news_tit);
                startActivity(intent);
            }
        });

    }


    private List<BookHomeListBean> newListBean2s;//新的列表集合，为加载更多服务
    private List<BookHomeListBean> allCacheData;//全部数据

    private int loadDataAllNumber = 6;//加载的数据总个数
    private int loadDataNumber = 6;//一次加载的数据个数，此处规定为6的倍数
    private int loadNumber = 2;//点击加载更多的次数

    private int surplusNumber;//总个数除以6，余下的个数

    private void getDataFromService1() {
        //http://www.wenqujingdian.com/
        showLoading(getActivity());

        //获取图书列表数据
        ViseHttp.GET("index.php/Jiekou/tjtushu")
//        ViseHttp.GET("index.php/jiekou/tjts")
                .tag(TAG)
                //.setHttpCache(true)
                //配置读取超时时间，单位秒
                .readTimeOut(60)
                //配置写入超时时间，单位秒
                .writeTimeOut(60)
                //配置连接超时时间，单位秒
                .connectTimeOut(60)
                //配置请求失败重试次数
                .retryCount(3)
                //配置请求失败重试间隔时间，单位毫秒
                .retryDelayMillis(1000)

                .setLocalCache(true)
                .cacheKey("recommendBook")
                .cacheTime(1 * 60 * 60 * 60 * 1000)
                .cacheMode(CacheMode.FIRST_CACHE)//先加载缓存，缓存没有再去请求网络

                .request(new ACallback<CacheResult<List<BookHomeListBean>>>() {
                    @Override
                    public void onSuccess(CacheResult<List<BookHomeListBean>> bookListBeans) {
                        Log.i(TAG, "onSuccess: ");
                        getDataFromService2();
                        //NiceDialogUtils.dismissNiceDialog();
                        allCacheData = bookListBeans.getCacheData();

                        if (allCacheData != null && allCacheData.size() > 0) {
                            //Log.i(TAG, "onSuccess: bookListBeans= " + bookListBeans.size());

                            surplusNumber = allCacheData.size() % loadDataNumber;

                            newListBean2s = new ArrayList<>();

                            if (allCacheData.size() > loadDataNumber) {
                                for (int i = 0; i < loadDataNumber; i++) {
                                    newListBean2s.add(allCacheData.get(i));
                                }
                                mAdapter1.setNewData(newListBean2s);
                            } else {
                                mAdapter1.setNewData(allCacheData);
                                mAdapter1.removeFooterView(footerView1);
                            }
                            getLunboData();
                            FenleiData();
                        } else {
                            mAdapter1.setNewData(null);
                            mAdapter1.setEmptyView(R.layout.comment_empty_view, (ViewGroup) mRecyclerView1.getParent());
                        }


                    }

                    @Override
                    public void onFail(int errCode, String errMsg) {
                        cancelLoading();
                        //请求失败，errCode为错误码，errMsg为错误描述
                        ToastUtil.showToast(errCode + " " + errMsg);
                        Log.i(TAG, "onFail: errCode" + errCode + " errMsg=" + errMsg);
                    }
                });


    }


    private List<BookHomeListBean> newListBean2s2;//新的列表集合，为加载更多服务
    private List<BookHomeListBean> allCacheData2;//全部数据

    private int loadDataAllNumber2 = 6;//加载的数据总个数
    private int loadDataNumber2 = 6;//一次加载的数据个数，此处规定为6的倍数
    private int loadNumber2 = 2;//点击加载更多的次数

    private int surplusNumber2;//总个数除以6，余下的个数

    private void getDataFromService2() {
        //http://www.wenqujingdian.com/index.php/Jiekou/yudubang
        //NiceDialogUtils.showNiceDialog(getChildFragmentManager());

        //获取图书列表数据
        ViseHttp.GET("index.php/Jiekou/yudubang")
                .tag(TAG)
                //.setHttpCache(true)
                //配置读取超时时间，单位秒
                .readTimeOut(60)
                //配置写入超时时间，单位秒
                .writeTimeOut(60)
                //配置连接超时时间，单位秒
                .connectTimeOut(60)
                //配置请求失败重试次数
                .retryCount(3)
                //配置请求失败重试间隔时间，单位毫秒
                .retryDelayMillis(1000)

                .setLocalCache(true)
                .cacheKey("yudubang")
                .cacheTime(1 * 60 * 60 * 60 * 1000)
                .cacheMode(CacheMode.FIRST_CACHE)//先加载缓存，缓存没有再去请求网络

                .request(new ACallback<CacheResult<List<BookHomeListBean>>>() {
                    @Override
                    public void onSuccess(CacheResult<List<BookHomeListBean>> bookListBeans) {
                        Log.i(TAG, "onSuccess: ");
                        getDataFromService3();
                        //NiceDialogUtils.dismissNiceDialog();
                        allCacheData2 = bookListBeans.getCacheData();

                        if (allCacheData2 != null && allCacheData2.size() > 0) {
                            //Log.i(TAG, "onSuccess: bookListBeans= " + bookListBeans.size());

                            surplusNumber2 = allCacheData2.size() % loadDataNumber2;

                            newListBean2s2 = new ArrayList<>();

                            if (allCacheData2.size() > loadDataNumber2) {
                                for (int i = 0; i < loadDataNumber2; i++) {
                                    newListBean2s2.add(allCacheData2.get(i));
                                }
                                mAdapter2.setNewData(newListBean2s2);
                            } else {
                                mAdapter2.setNewData(allCacheData2);
                                mAdapter2.removeFooterView(footerView2);
                            }


                        } else {
                            mAdapter2.setNewData(null);
                            mAdapter2.setEmptyView(R.layout.comment_empty_view, (ViewGroup) mRecyclerView2.getParent());
                        }


                    }

                    @Override
                    public void onFail(int errCode, String errMsg) {
                        cancelLoading();
                        //请求失败，errCode为错误码，errMsg为错误描述
                        ToastUtil.showToast(errCode + " " + errMsg);
                        Log.i(TAG, "onFail: errCode" + errCode + " errMsg=" + errMsg);
                    }
                });


    }


    private List<BookHomeListBean> newListBean2s3;//新的列表集合，为加载更多服务
    private List<BookHomeListBean> allCacheData3;//全部数据

    private int loadDataAllNumber3 = 6;//加载的数据总个数
    private int loadDataNumber3 = 6;//一次加载的数据个数，此处规定为6的倍数
    private int loadNumber3 = 2;//点击加载更多的次数

    private int surplusNumber3;//总个数除以6，余下的个数

    private void getDataFromService3() {
        //www.wenqujingdian.com/index.php/Jiekou/newbook
        //NiceDialogUtils.showNiceDialog(getChildFragmentManager());

        //获取图书列表数据
        ViseHttp.GET("index.php/Jiekou/newbook")
                .tag(TAG)
                //.setHttpCache(true)
                //配置读取超时时间，单位秒
                .readTimeOut(60)
                //配置写入超时时间，单位秒
                .writeTimeOut(60)
                //配置连接超时时间，单位秒
                .connectTimeOut(60)
                //配置请求失败重试次数
                .retryCount(3)
                //配置请求失败重试间隔时间，单位毫秒
                .retryDelayMillis(1000)

                .setLocalCache(true)
                .cacheKey("newbook")
                .cacheTime(1 * 60 * 60 * 60 * 1000)
                .cacheMode(CacheMode.FIRST_CACHE)//先加载缓存，缓存没有再去请求网络

                .request(new ACallback<CacheResult<List<BookHomeListBean>>>() {
                    @Override
                    public void onSuccess(CacheResult<List<BookHomeListBean>> bookListBeans) {
                        Log.i(TAG, "onSuccess: ");
                        cancelLoading();
                        allCacheData3 = bookListBeans.getCacheData();

                        if (allCacheData3 != null && allCacheData3.size() > 0) {
                            //Log.i(TAG, "onSuccess: bookListBeans= " + bookListBeans.size());

                            surplusNumber3 = allCacheData3.size() % loadDataNumber3;

                            newListBean2s3 = new ArrayList<>();

                            if (allCacheData3.size() > loadDataNumber3) {
                                for (int i = 0; i < loadDataNumber3; i++) {
                                    newListBean2s3.add(allCacheData3.get(i));
                                }
                                mAdapter3.setNewData(newListBean2s3);
                            } else {
                                mAdapter3.setNewData(allCacheData3);
                                mAdapter3.removeFooterView(footerView3);
                            }
                        } else {
                            mAdapter3.setNewData(null);
                            mAdapter3.setEmptyView(R.layout.comment_empty_view, (ViewGroup) mRecyclerView3.getParent());
                        }


                    }

                    @Override
                    public void onFail(int errCode, String errMsg) {
                        cancelLoading();
                        //请求失败，errCode为错误码，errMsg为错误描述
                        ToastUtil.showToast(errCode + " " + errMsg);
                        Log.i(TAG, "onFail: errCode" + errCode + " errMsg=" + errMsg);
                    }
                });
    }

    private void getLunboData() {
        listUrl.clear();
        listUrl.add(R.mipmap.banner01);
        listUrl.add(R.mipmap.banner02);
        listUrl.add(R.mipmap.banner03);
        getCarousel();
    }

    /**
     * 轮播
     */
    private void getCarousel() {
        //设置图片加载器
        banner.setImageLoader(new GlideImageLoader());
        //设置图片集合
        banner.setImages(listUrl);
        //banner设置方法全部调用完毕时最后调用
        banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);
        banner.setBannerAnimation(Transformer.CubeOut);
        banner.setOnBannerListener(this);
        banner.start();
    }

    private void FenleiData() {
        fenleiHomeBeanList.clear();
        String json = AssetsUtils.readJson(MyApplication.mContext, "home_fenlei.json");
        HomeFenBean homeFenBean = GsonUtil.GsonToBean(json, HomeFenBean.class);
        //5个分类
        fenleiHomeBeanList.addAll(homeFenBean.getObj().getFenleiList());
        fenleiAdapter.notifyDataSetChanged();
    }

    private View footerView1;
    private View footerView2;
    private View footerView3;

    private Banner banner;

    //banner
    private View getHeaderView1() {
        View view = getLayoutInflater().inflate(R.layout.a_home1, (ViewGroup) mRecyclerView1.getParent(), false);
        banner = view.findViewById(R.id.banner);
        return view;
    }

    //分类
    private View getHeaderView2() {
        View view = getLayoutInflater().inflate(R.layout.a_home5, (ViewGroup) mRecyclerView1.getParent(), false);
        //分类
        fenleiRecyclerView = view.findViewById(R.id.fenlei_recyclerview);
        ScrollGridLayoutManager scrollGridLayoutManager1 = new ScrollGridLayoutManager(getActivity(), 4);
        scrollGridLayoutManager1.setScrollEnable(false);
        fenleiRecyclerView.setLayoutManager(scrollGridLayoutManager1);
        //fenleiRecyclerView.addItemDecoration(new CustomDecoration(getActivity(), CustomDecoration.VERTICAL_LIST, R.drawable.recyclerview_divider_thin, DPUtil.dp2px(getActivity(), 10)));
        fenleiAdapter = new HomeFenleiAdapter(getActivity(), R.layout.gallery_item_image, fenleiHomeBeanList);
        fenleiAdapter.openLoadAnimation(BaseQuickAdapter.SLIDEIN_LEFT);//添加动画
        fenleiRecyclerView.setAdapter(fenleiAdapter);
        //fenleiAdapter.setOnItemClickListener(this);
        fenleiAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                switch (position) {
                    case 0:
                        startIn("阅享馆");
                        break;
                    case 1:
                        startIn("听书馆");
                        break;
                    case 2:
                        startIn("期刊馆");
                        break;
                    case 3:
                        startIn("日习馆");
                        break;
                    case 4:
                        startIn("体验馆");
                        break;
                    case 5:
                        // startIn("书友会");
                        startActivity(new Intent(getActivity(), ShuyouhuiActivity.class));
                        break;
                    case 6:
                        Intent intent = new Intent(getActivity(), MainActivity.class);
                        intent.putExtra("shujia", true);
                        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        MyApplication.flagShujia = true;
                        startActivity(intent);
                        break;
                    case 7:
//                        Intent intent1 = new Intent(getActivity(), MainActivity.class);
//                        intent1.putExtra("mine", true);
//                        intent1.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//                        MyApplication.flagMine = true;
//                        startActivity(intent1);
                        onScanQR();
                        break;
                }
            }
        });
        return view;
    }

    /**
     * 进入扫描二维码页面
     */
    public void onScanQR() {
        QRCodeManager.getInstance()
                .with(getActivity())
                .setReqeustType(0)
                .scanningQRCode(new OnQRCodeListener() {
                    @Override
                    public void onCompleted(String result) {
                        Log.i("huidiao", "\n\n(结果)" + result);
//                        getQRcodeSucess(result);
                    }

                    @Override
                    public void onError(Throwable errorMsg) {
                        Log.i("huidiao", "\n\n(错误)" + errorMsg.toString());
                        ToastUtil.showToast("错误：-->" + errorMsg.toString());
                    }

                    @Override
                    public void onCancel() {
                        Log.i("huidiao", "\n\n(取消)扫描任务取消了");
                    }

                });
    }

    private void startIn(String typeF) {
        Intent s = new Intent(getActivity(), MiddleActivity.class);
        s.putExtra("type", typeF);
        startActivity(s);
    }


    private View getFooterView1(View.OnClickListener listener) {
        footerView1 = getActivity().getLayoutInflater().inflate(R.layout.foot_view_layout, (ViewGroup) mRecyclerView1.getParent(), false);
        footerView1.setOnClickListener(listener);
        return footerView1;
    }

    private View getFooterView2(View.OnClickListener listener) {
        footerView2 = getActivity().getLayoutInflater().inflate(R.layout.foot_view_layout, (ViewGroup) mRecyclerView2.getParent(), false);
        footerView2.setOnClickListener(listener);
        return footerView2;
    }

    private View getFooterView3(View.OnClickListener listener) {
        footerView3 = getActivity().getLayoutInflater().inflate(R.layout.foot_view_layout, (ViewGroup) mRecyclerView3.getParent(), false);
        footerView3.setOnClickListener(listener);
        return footerView3;
    }

    @Override
    public void onStart() {
        super.onStart();
        if (banner != null) {
            banner.startAutoPlay();
        }
    }

    @Override
    public void onStop() {
        super.onStop();
        if (banner != null) {
            banner.stopAutoPlay();
        }
    }

    @Override
    public void OnBannerClick(int position) {
        switch (position) {
            case 0:
                //  ToastUtil.show("1");
                break;
            case 1:
                //  ToastUtil.show("2");
                break;
            case 2:
                //  ToastUtil.show("3");
                break;
        }
    }
}
